package calorie.com.calorie.contact;


import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;


import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.request.ForgetLoginPasswordRequest;
import calorie.com.calorie.request.SendCodeRequest;
import calorie.com.calorie.response.ResultDTO;
import retrofit2.Call;
import retrofit2.Response;

public class ForgetLoginPasswordContact {
    public static class ForgetLoginPasswordPresent extends BasePresent<IForgetLoginPasswordView> {
        public void forgetLoginPassword( String account, String phone,String newLoginPassword,String yzm){
            ApiService service= ServiceGenerator.createService(ApiService.class);
            ForgetLoginPasswordRequest request=new ForgetLoginPasswordRequest(account,phone, Md5Utils.stringToMD5(newLoginPassword),yzm);
            service.forgetLoginPassword(request).enqueue(new NetCallBack<ResultDTO>() {

                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView()!=null){
                        getView().getResult(response);
                    }
                }

                @Override
                public void onFailed() {
                    if (getView()!=null){
                        getView().getDataFailed();
                    }
                }
            });

        }
        public void getCode(String phone,String account){
            ApiService service=ServiceGenerator.createService(ApiService.class);
            SendCodeRequest sendCodeRequest = new SendCodeRequest(phone,account,"2");
            service.sendCode(sendCodeRequest).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView()!=null){
                        getView().getSendCodeResult(response);
                    }
                }

                @Override
                public void onFailed() {
                    if (getView()!=null){
                        getView().getDataFailed();
                    }
                }
            });
        }

    }


    public interface IForgetLoginPasswordView extends IBaseView {
        void getResult(Response<ResultDTO> response);
        void getDataFailed();
        void  getSendCodeResult(Response<ResultDTO> responseResponse);
    }


}
